/*
* 数据服务接口
* */

import Vue from 'vue'
import axios from 'axios'
import qs from 'qs'


const star = function(callback){
  axios.get("http://localhost:8390/api/score").then( res =>{
    callback(res.data.code);
  } )
}

const getDemoName = (addr,callback) => {
  Vue.jsonp("http://localhost:8390/api/hello",{addr:addr}).then(json=>{
    callback(json.name);
  }).catch(err=>{});
}

const login = (username,password,callback) =>{
  let data = qs.stringify({
    username:username,
    password:password
  })
  axios.post("http://localhost:8390/api/login",data).then( res =>{
    callback(res.data);
  } )
}

const logout = (callback) =>{
  axios.get("http://localhost:8390/api/logout").then( res =>{
    callback(res.data);
  } )
}


export {
  star,
  getDemoName,
  login,
  logout
}
